﻿using System.ComponentModel;
using System.Linq;

namespace Colorful.Furniture.FinanceSdk
{
    public struct ChatDatas
    {
        public int errcode;
        public string errmsg;
        public ChatData[] chatdata;
    }

    public struct ChatData
    {
        public long seq;
        public string msgid;
        public int publickey_ver;
        public string encrypt_random_key;
        public string encrypt_chat_msg;
    }

    public class MsgType
    {
        [Description("[文本消息]")] public const string Text = "text";
        [Description("[图片]")] public const string Image = "image";
        [Description("[撤回消息]")] public const string Revoke = "revoke";
        [Description("[其他消息]")] public const string Agree = "agree";
        [Description("[其他消息]")] public const string Disagree = "disagree";
        [Description("[语音]")] public const string Voice = "voice";
        [Description("[视频]")] public const string Video = "video";
        [Description("[名片]")] public const string Card = "card";
        [Description("[位置]")] public const string Location = "location";
        [Description("[自定义表情]")] public const string Emotion = "emotion";
        [Description("[文件]")] public const string File = "file";
        [Description("[链接]")] public const string Link = "link";
        [Description("[小程序消息]")] public const string WeApp = "weapp";
        [Description("[聊天记录]")] public const string ChatRecord = "chatrecord";
        [Description("[待办消息]")] public const string Todo = "todo";
        [Description("[投票消息]")] public const string Vote = "vote";
        [Description("[填表消息]")] public const string Collect = "collect";
        [Description("[红包消息]")] public const string RedPacket = "redpacket";
        [Description("[会议邀请]")] public const string Meeting = "meeting";
        [Description("[切换企业]")] public const string Switch= "switch";
        [Description("[在线文档]")] public const string DocMsg = "docmsg";
        [Description("[MarkDown]")] public const string Markdown = "markdown";
        [Description("[图文消息]")] public const string News = "news";
        [Description("[日程消息]")] public const string Calendar = "calendar";
        [Description("[混合消息]")] public const string Mixed = "mixed";
        [Description("[音频存档消息]")] public const string MeetingVoiceCall = "meeting_voice_call";
        [Description("[音频共享消息]")] public const string VoipDocShare = "voip_doc_share";
        [Description("[互通红包消息]")] public const string ExternalRedPacket = "external_redpacket";
        [Description("[视频号]")] public const string SphFeed = "sphfeed";


        public static string GetDescription(string str)
        {
            var type = new MsgType();
            var prop = type.GetType().GetFields().FirstOrDefault(p => p.GetValue(type).ToString() == str);
            if (prop == null)
                return "[未知消息]";

            var attrs = prop.GetCustomAttributes(typeof(DescriptionAttribute), false);
            if(!attrs.Any())
                return "[未知消息]";
            var desc = (DescriptionAttribute)attrs[0];
            return desc.Description;
        }
    }


    public interface ISendable
    {

    }
    public class Chat: ISendable
    {
        public string msgid { get; set; }
        public string action { get; set; }
        public string from { get; set; }
        public string[] tolist { get; set; }
        public string roomid { get; set; }
        public long msgtime { get; set; }
        public string msgtype { get; set; }
    }

    public class ChatText : Chat
    {
        public ChatTextDetail text { get; set; }
    }
    public class ChatTextDetail
    {
        public string content { get; set; }
    }

    public class ChatImage : Chat
    {
        public ChatImageDetail image { get; set; }
    }
    public class ChatImageDetail
    {
        public string md5sum { get; set; }
        public string sdkfileid { get; set; }
        public int filesize { get; set; }
    }

    public class ChatRevoke: Chat
    {
        public ChatRevokeDetail revoke { get; set; }
    }
    public class ChatRevokeDetail
    {
        public string pre_msgid { get; set; }
    }

    public class ChatAgree:Chat
    {
        public ChatAgreeDetail agree { get; set; }
    }
    public class ChatAgreeDetail
    {
        public string userid { get; set; }
        public long agree_time { get; set; }
    }

    public class ChatDisagree:Chat
    {
        public ChatDisagreeDetail disagree { get; set; }
    }
    public class ChatDisagreeDetail
    {
        public string userid { get; set; }
        public long disagree_time { get; set; }
    }

    public class ChatVoice : Chat
    {
        public ChatVoiceDetail voice { get; set; }
    }
    public class ChatVoiceDetail
    {
        public int voice_size { get; set; }
        public int play_length { get; set; }
        public string sdkfileid { get; set; }
        public string md5sum { get; set; }
    }

    public class ChatVideo : Chat
    {
        public ChatVideoDetail video { get; set; }
    }
    public class ChatVideoDetail
    {
        public int file_size { get; set; }
        public int play_length { get; set; }
        public string sdkfileid { get; set; }
        public string md5sum { get; set; }
    }

    public class ChatCard : Chat
    {
        public ChatCardDetail card { get; set; }
    }
    public class ChatCardDetail
    {
        public string corpname { get; set; }
        public string userid { get; set; }
    }

    public class ChatLocation : Chat
    {
        public ChatLocationDetail location { get; set; }
    }
    public class ChatLocationDetail
    {
        public double longitude { get; set; }
        public double latitude { get; set; }
        public string address { get; set; }
        public string title { get; set; }
        public int zoom { get; set; }
    }

    public class ChatEmotion : Chat
    {
        public ChatEmotionDetail emotion { get; set; }
    }
    public class ChatEmotionDetail
    {
        public int type { get; set; }
        public int width { get; set; }
        public int height { get; set; }
        public string sdkfileid { get; set; }
        public string md5sum { get; set; }
        public int imagesize { get; set; }
    }

    public class ChatFile : Chat
    {
        public ChatFileDetail file { get; set; }
    }
    public class ChatFileDetail
    {
        public string sdkfileid { get; set; }
        public string md5sum { get; set; }
        public string filename { get; set; }
        public string fileext { get; set; }
        public int filesize { get; set; }
    }

    public class ChatLink : Chat
    {
        public ChatLinkDetail link { get; set; }
    }
    public class ChatLinkDetail
    {
        public string title { get; set; }
        public string description { get; set; }
        public string link_url { get; set; }
        public string image_url { get; set; }
    }

    public class ChatWeApp : Chat
    {
        public ChatWeAppDetail weapp { get; set; }
    }
    public class ChatWeAppDetail
    {
        public string title { get; set; }
        public string description { get; set; }
        public string username { get; set; }
        public string displayname { get; set; }
    }

    public class ChatChatRecord : Chat
    {
        public ChatChatRecordDetail chatrecord { get; set; }
    }
    public class ChatChatRecordDetail
    {
        public string title { get; set; }
        public ChatChatRecordItem[] item { get; set; }
    }
    public class ChatChatRecordItem
    {
        public string type { get; set; }
        public long msgtime { get; set; }
        public string content { get; set; }
        public bool from_chatroom { get; set; }
    }

    public class ChatTodo : Chat
    {
        public ChatTodoDetail todo { get; set; }
    }
    public class ChatTodoDetail
    {
        public string title { get; set; }
        public string content { get; set; }
    }

    public class ChatVote : Chat
    {
        public ChatVoteDetail vote { get; set; }
    }
    public class ChatVoteDetail
    {
        public string votetitle { get; set; }
        public string voteitem { get; set; }
        public int votetype { get; set; }
        public string voteid { get; set; }
    }

    public class ChatCollect : Chat
    {
        public ChatCollectDetail collect { get; set; }
    }
    public class ChatCollectDetail
    {
        public string RoomName { get; set; }
        public string Creator { get; set; }
        public string CreateTime { get; set; }
        public string Title { get; set; }
        public string Details { get; set; }
        public long Id { get; set; }
        public string Ques { get; set; }
        public string Type { get; set; }
    }

    public class ChatRedPacket : Chat
    {
        public ChatRedPacketDetail redpacket { get; set; }
    }
    public class ChatRedPacketDetail
    {
        public int type { get; set; }
        public string wish { get; set; }
        public int totalcnt { get; set; }
        public int totalamount { get; set; }
    }

    public class ChatMeeting : Chat
    {
        public ChatMeetingDetail meeting { get; set; }
    }
    public class ChatMeetingDetail
    {
        public string topic { get; set; }
        public long starttime { get; set; }
        public long endtime { get; set; }
        public string address { get; set; }
        public string remarks { get; set; }
        public int meetingtype { get; set; }
        public long meetingid { get; set; }
        public int status { get; set; }
    }

    public class ChatSwitch : ISendable
    {
        public string msgid { get; set; }
        public string action { get; set; }
        public long time { get; set; }
        public string user { get; set; }
    }

    public class ChatDocMsg: Chat
    {
        public ChatDocMsgDetail doc { get; set; }
    }
    public class ChatDocMsgDetail
    {
        public string title { get; set; }
        public string link_url { get; set; }
        public string doc_creator { get; set; }
    }

    public class ChatMarkDown : Chat
    {
        public ChatMarkDownDetail info { get; set; }
    }
    public class ChatMarkDownDetail
    {
        public string content { get; set; }
    }

    public class ChatNews: Chat
    {
        public ChatNewsDetail info { get; set; }
    }
    public class ChatNewsDetail
    {
        public ChatNewsItem[] item { get; set; }
    }
    public class ChatNewsItem
    {
        public string title { get; set; }
        public string description { get; set; }
        public string url { get; set; }
        public string picurl { get; set; }
    }

    public class ChatCalendar : Chat
    {
        public ChatCalendarDetail calendar { get; set; }
    }
    public class ChatCalendarDetail
    {
        public string title { get; set; }
        public string creatorname { get; set; }
        public string attendeename { get; set; }
        public long starttime { get; set; }
        public long endtime { get; set; }
        public string place { get; set; }
        public string remarks { get; set; }
    }

    public class ChatMixed : Chat
    {
        public ChatMixedDetail mixed { get; set; }
    }
    public class ChatMixedDetail
    {
        public ChatMixedItem[] item { get; set; }
    }
    public class ChatMixedItem
    {
        public string type { get; set; }
        public string content { get; set; }
    }

    public class ChatMeetingVoiceCall : Chat
    {
        //TODO
    }

    public class ChatVoipDocShare : Chat
    {
        //TODO
    }

    public class ChatExternalRedPacket : Chat
    {
        public ChatExternalRedPacketDetail redpacket { get; set; }
    }
    public class ChatExternalRedPacketDetail
    {
        public int type { get; set; }
        public string wish { get; set; }
        public int totalcnt { get; set; }
        public int totalamount { get; set; }
    }

    public class ChatSphFeed: Chat
    {
        public ChatSphFeedDetail shpfeed { get; set; }
    }
    public class ChatSphFeedDetail
    {
        public int feed_type { get; set; }
        public int sph_name { get; set; }
        public string feed_desc { get; set; }
    }
}
